<!DOCTYPE html>
<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <!-- Meta, title, CSS, favicons, etc. -->
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <title>HRs! </title>

  <!-- Bootstrap -->
  <link href="../vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
  <!-- Font Awesome -->
  <link href="../vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet">
  <!-- NProgress -->
  <link href="../vendors/nprogress/nprogress.css" rel="stylesheet">
  <!-- Animate.css -->
  <link href="../vendors/animate.css/animate.min.css" rel="stylesheet">

  <!-- Custom Theme Style -->
  <link href="../build/css/custom.min.css" rel="stylesheet">
</head>

<body class="login">
  <div>
    <a class="hiddenanchor" id="signup"></a>
    <a class="hiddenanchor" id="signin"></a>

    <div class="login_wrapper">
      <div class="animate form login_form">
        <section class="login_content">
          <form>
            <h1>Login Form</h1>
            <div>
              <input type="text" name="username" class="form-control" placeholder="Username" required="" id="username"/>
            </div>
            <div>
              <input type="password" name="password" class="form-control" placeholder="Password" required="" id="password"/>
            </div>
            <div>
              <a class="btn btn-default submit"  onclick="login()">Log in</a>
              <a class="reset_pass" href="#">Lost your password?</a>
            </div>

            <div class="clearfix"></div>

            <div class="separator">
              <p class="change_link">New to site?
                <a href="#signup" class="to_register"> Create Account </a>
              </p>

              <div class="clearfix"></div>
              <br />


            </div>
          </form>
        </section>
      </div>

      <div id="register" class="animate form registration_form">
        <section class="login_content">
          <form>
            <h1>Create Account</h1>
            <div>
              <input type="text" class="form-control" placeholder="Username" required="" id="Username" />
            </div>
            <div>
              <input type="email" class="form-control" placeholder="Company" required="" id="Company" />
            </div>
            <div>
              <input type="password" class="form-control" placeholder="Password" required="" id="Password" />
            </div>
            <div>
              <a class="btn btn-default submit" onclick="Submit()">Submit</a>
            </div>

            <div class="clearfix"></div>

            <div class="separator">
              <p class="change_link">Already a member ?
                <a href="#signin" class="to_register"> Log in </a>
              </p>

              <div class="clearfix"></div>
              <br />


            </div>
          </form>
        </section>
      </div>
    </div>
  </div>



  <!-- jQuery -->
  <script src="../vendors/jquery/dist/jquery.min.js"></script>
  <script src="./js/utils.js"></script>

    <!-- <script src="https://unpkg.com/axios/dist/axios.min.js"> -->
  <script>
    // function login(){
    // let account=document.getElementById("username").value;
    // let password=document.getElementById("password").value;
    // axios.post('http://172.20.10.4:8080/user/login', {
    //     username: account,
    //     password: password
    //   })
    //   .then(function (response) {
    //     console.log(response);
    //     if(response.data.status==200){
    //        window.location.href="index.html";
    //     }else{
    //        alert("账户密码错误“）；
    //      }
    // })
    //   .catch(function (error) {
    //     console.log(error);
    //   });
    let user = localStorage.getItem("user");
    user = JSON.parse(user);
    if (user != null) {
      localStorage.setItem("user", null);
    }

    function login() {
      console.log(11111);
      let data = {
        account: '',
        password: ''
      }
      data.account = document.getElementById("username").value == null || document.getElementById("username").value == '' ? null : document.getElementById("username").value;;
      data.password = document.getElementById("password").value == null || document.getElementById("password").value == '' ? null : document.getElementById("password").value;
      let re = rqeuest("/user/login", 'POST', data);
      if (re.code == 0) {
        console.log(2222);
        alert(re.message);
        // console.log(re);
        localStorage.setItem("token", JSON.stringify(re.data.token));
        localStorage.setItem("user", JSON.stringify(re.data.user));
        window.location.href = "index.html";
      }else {
        alert(re.message);
      }
    }

    function Submit() {
      let data = {
        account: '',
        password: '',
        company: ''
      }
      data.account = document.getElementById("Username").value == null || document.getElementById("Username").value == '' ? null : document.getElementById("Username").value;;
      data.password = document.getElementById("Password").value == null || document.getElementById("Password").value == '' ? null : document.getElementById("Password").value;
      data.company = document.getElementById("Company").value == null || document.getElementById("Company").value == '' ? null : document.getElementById("Company").value;
      let re = rqeuest("/user/register", 'POST', data);
      if (re.code == 0) {
        alert(re.message);
        window.location.href = "login.html";
      }else {
        alert(re.message);
      }
    }
  </script>

</body>

</html>
</div>
</div>
</div>